package se.sll.itintegration.catalogue.gui.service.view.capacity;

import se.sll.service.catalogue.common.Translator;
import se.sll.service.catalogue.common.data.UnitId;
import se.sll.service.catalogue.common.data.UnitList;

/**
 * Translates from CapacityView to UnitList.
 * 
 * @author Christer Palm, Nogui
 */
public class CapacityViewUnitListTranslator implements Translator<CapacityView, UnitList> {
    private static final CapacityViewUnitListTranslator INSTANCE = new CapacityViewUnitListTranslator();

    private CapacityViewUnitListTranslator() {
    }

    @Override
    public UnitList translate(CapacityView from) {
        return translateTo(from, new UnitList());
    }

    @Override
    public UnitList translateTo(CapacityView from, UnitList to) {
        for (CapacityViewUnit unit : from.getCapacity()) {
            String hsaId = unit.getHsaID();
            UnitId unitId = new UnitId(hsaId);
            to.addUnit(unitId);
        }
        return to;
    }

    public static CapacityViewUnitListTranslator getInstance() {
        return INSTANCE;
    }
}
